{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "48d8a14e-2817-4eb4-b143-3ef484b21a64",
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install tiktoken"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a956fa49-0449-4838-8a82-c8befeed6c74",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tiktoken"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ae32001c-2c10-4eb9-bfbd-42c30ecc1805",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Encoding 'cl100k_base'>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "encoding = tiktoken.encoding_for_model(\"gpt-3.5-turbo\")\n",
    "encoding"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "08620582-66ee-402b-a56b-be2da7077e80",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[30868, 226, 31106, 111, 55030, 53610, 36827, 17905, 37507]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "encoding.encode(\"黄河之水天上来\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "373592f1-4d09-4e81-9dfc-c761acb52711",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(encoding.encode(\"黄河之水天上来\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e947457-e7ef-4798-b40c-f96b995ed77a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
